package com.nodecollege.cloud.controller.admin;

import com.nodecollege.cloud.common.annotation.ApiAnnotation;
import com.nodecollege.cloud.common.model.LoginAdmin;
import com.nodecollege.cloud.common.model.NCResult;
import com.nodecollege.cloud.common.model.po.UpmsAdmin;
import com.nodecollege.cloud.common.model.vo.LoginVO;
import com.nodecollege.cloud.common.utils.ThreadAdminUtils;
import com.nodecollege.cloud.common.annotation.AdminLoginAnnotation;
import com.nodecollege.cloud.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员中心
 * @author LC
 * @date 2019/12/2 20:47
 */
@RestController
@RequestMapping("/admin/centre")
public class AdminCentreController {

    @Autowired
    private AdminService adminService;

    /**
     * 修改密码
     *
     * @param loginVO
     */
    @ApiAnnotation(modularName = "管理员中心", description = "修改密码")
    @PostMapping("/updatePassword")
    public NCResult updatePassword(@RequestBody LoginVO loginVO){
        adminService.updateAdminPassword(loginVO.getAccount(), loginVO.getPassword(), loginVO.getNewPassword(), loginVO.getImageCert());
        return NCResult.ok();
    }

    /**
     * 修改个人信息
     *
     * @param admin
     * @return
     */
    @ApiAnnotation(modularName = "管理员中心", description = "修改个人信息")
    @AdminLoginAnnotation
    @PostMapping("/updateInfo")
    public NCResult updateInfo(@RequestBody UpmsAdmin admin) {
        // 获取当前登录人信息
        LoginAdmin loginAdmin = ThreadAdminUtils.getLoginAdmin();
        admin.setAdminId(loginAdmin.getUserId());
        adminService.updateAdmin(admin);
        return NCResult.ok();
    }
}
